local desc_doublekj_mode = [[
  # 抗金简介
  ___

  2个玩家（身份固定为主忠，玩家不足人机补位）对抗2个人机（身份固定为反贼）。当所有反贼死亡后，它们将换将复活并强化然后战斗下一轮挑战组人机直到满足胜利或失败条件。

  胜利条件：反贼全部阵亡且达到设定的挑战组。

  失败条件：主忠全部阵亡。

  战功设定：游戏开始，所有主忠角色获得【战功】技能：锁定技，当你获得某些标记能够强化自身。
    强化标记有：摸牌阶段额外摸牌+x，手牌上限+x，每轮开始获得护盾+x，出牌阶段额外使用杀次数+x，额外杀目标数+x。（x为获得的对应标记数）

  斩将设定：每次出现反贼武将将有概率获得【斩将】技能：锁定技，当你死亡时，杀死你的角色（要有【战功】技能）从3个随机的强化标记选项中选1个获得。

]]
-- local XlkjObj = require "packages/xlkj/XlkjObj"
local U = require "packages/utility/utility"
local SelGenMuty = require "packages/lang/SelGenMuty"
local KJobj = require "packages/lang/KJobj"

--开启测试
local IStest
--下一轮战斗准备数据
local nextBattleData = {
  {
    xiandengnum = 0,
    getsameskills = {lord = {"kj_gongjue"},loyalist = {"kj_gongjue"}},
    deadthsing = {rebel = {1,1}},
  },
  {
    xiandengnum = 1,
    getsameskills = {rebel = {"rongzhuangSkill"}},
    getcardnum = {rebel=5,loyalist=2,lord=2},
    getshield = {rebel = 1},
    deadthsing = {rebel = {1,1}},
    rongzhuangnum = {rebel = 1}
  },
  {
    xiandengnum = 2,
    getsameskills = {rebel = {"rongzhuangSkill","ex__yingzi"}},
    getcardnum = {rebel=6,loyalist=2,lord=2},
    getmaxhp = {rebel = 1},
    getshield = {rebel = 1},
    deadthsing = {rebel = {1,1}},
    rongzhuangnum = {rebel = 1}
  },
  -- {
  --   xiandengnum = 1,
  --   getcardnum = {rebel=6,lord = 2,loyalist=2},
  --   getmaxhp = {rebel=1},
  --   getsameskills = {rebel = {"rongzhuangSkill"}},
  --   deadthsing = {rebel = {1,1}},
  --   rongzhuangnum = {rebel = 2}
  -- },
  -- {
  --   xiandengnum = 2,
  --   getcardnum = {rebel=5,lord = 2,loyalist=2},
  --   getmaxhp = {rebel=1},
  --   getsameskills = {rebel = {"rongzhuangSkill"}},
  --   deadthsing = {rebel = {1,1}},
  --   rongzhuangnum = {rebel = 2}
  -- },
  -- {
  --   xiandengnum = 3,
  --   getcardnum = {rebel=6,lord = 2,loyalist=2},
  --   getmaxhp = {rebel=2},
  --   getsameskills = {rebel = {"ex__yingzi","rongzhuangSkill"}},
  --   deadthsing = {rebel = {1,1}},
  --   rongzhuangnum = {rebel = 2}
  -- },
  -- {
  --   xiandengnum = 3,
  --   getcardnum = {rebel=6,lord = 3,loyalist=3},
  --   getmaxhp = {rebel=3},
  --   getsameskills = {rebel = {"m_ex__dangxian","rongzhuangSkill"}},
  --   deadthsing = {rebel = {1,1}},
  --   rongzhuangnum = {rebel = 2}
  -- },
  -- {
  --   xiandengnum = 4,
  --   getcardnum = {rebel=6,lord = 3,loyalist=3},
  --   getmaxhp = {rebel=3},
  --   getsameskills = {rebel = {"yingjian","chouce","rongzhuangSkill"}},
  --   deadthsing = {rebel = {1,1}},
  --   rongzhuangnum = {rebel = 2}
  -- },
}
--战斗轮数
local battleTurn = #nextBattleData
--当前轮数
local curTurn = 1
--过滤其他卡组（只允许白名单的卡组加入牌堆）
local WHILEcards = {"standard","standard_cards","maneuvering","lang_cards","tenyear_token","mobile_derived","ol_token","overseas_token"}

local doublekj_getLogic = function()
  local doublekj_logic = GameLogic:subclass("doublekj_logic")

  function doublekj_logic:initialize(room)
    GameLogic.initialize(self, room)
    self.role_table = {
      { "lord" },
      { "lord", "rebel" },
      { "lord", "rebel", "rebel" },
      { "lord", "loyalist", "rebel", "rebel" },
      { "lord", "loyalist", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "loyalist", "rebel", "rebel" },
      { "lord", "rebel", "rebel", "rebel", "rebel", "rebel", "rebel" },
      { "lord", "loyalist", "loyalist", "rebel", "rebel", "rebel", "rebel", "loyalist" },
    }
    room.KJobj = KJobj:new({
      nextBattleData = nextBattleData,
      rebles = 2,
      maxplayers = 2,
      istest = IStest,
    })
  end

  function doublekj_logic:prepareForStart()
    self.room:setTag("@curturn",curTurn)
    self.room:setTag("@battleturn",battleTurn)
    self.room.KJobj:logic_prepareForStart({
      otherbanners = {{"@[:]doublekjbaner_rule","doublekj-intro"},{"@totalbattle",curTurn.."/"..battleTurn},{"@seefriendcardstart",""}}
    })
  end

  function doublekj_logic:prepareDrawPile()
    self.room.KJobj:logic_prepareDrawPile({
      excepts = {"lightning","crossbow"},
      whitecards = WHILEcards
    })
  end

  function doublekj_logic:assignRoles()
    self.room.KJobj:logic_assignRoles({
      role_table = self.role_table,
    })
  end

  function doublekj_logic:chooseGenerals()
    local room = self.room
    local lord = room:getLord()
    room.current = lord

    SelGenMuty:new({
      generalNum=5,
      repcount = 4,
      istest = IStest,
      openhobbygens = true,
      genpoolname = "NOR_XLKJ",
      -- aipoolname = "MN_XLKJ"
    })
  end
  return doublekj_logic
end
---------------------------------------技能--------------------------------------------
local doublekj_rule = fk.CreateTriggerSkill{
  name = "#doublekj_rule",
  priority = 0.001,
  refresh_events = {fk.RoundStart,fk.BuryVictim,fk.GameStart,fk.GameOverJudge,fk.DrawInitialCards,fk.GamePrepared,fk.HpChanged,fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    if event == fk.HpChanged then
      if player == target and player.room.seeskinman then
        local ret = player.room.KJobj:HpChangedEvt(player)
        if ret then
          self.cost_data = ret
          return true
        end
      end 
      return 
    end
    if event == fk.RoundStart or event == fk.GameStart or event == fk.GamePrepared then
      return player.role == "lord"
    elseif event == fk.BuryVictim or event == fk.Deathed or event == fk.GameOverJudge then
      return player == target
    elseif event == fk.DrawInitialCards then
      return player == target and player.id < 0 and player.room:getTag("rebotdrawnum") and player.room:getTag("rebotdrawnum") > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      room.KJobj:roundStart()
    elseif event == fk.Deathed then
      room.KJobj:deaThed(data.who)
    elseif event == fk.BuryVictim then
      room.KJobj:buryVictim(data.who)
    elseif event == fk.GameOverJudge then
      room.KJobj:gameOverJudge()
    elseif event == fk.GameStart then
      room.KJobj:gameStart()
    elseif event == fk.GamePrepared then
      room.KJobj:gamePrepared()
    elseif event == fk.DrawInitialCards then
      room.KJobj:drawInitialCards(data)
    elseif event == fk.HpChanged then
      room.KJobj:changeSkin(player,self.cost_data)
    end
  end,
}
Fk:addSkill(doublekj_rule)

local doublekj_mode = fk.CreateGameMode{
  name = "doublekj_mode",
  minPlayer = 4,
  maxPlayer = 4,
  rule = doublekj_rule,
  logic = doublekj_getLogic,
  whitelist = table.clone(WHILEcards),
  winner_getter = function(self, victim)
    return ""
  end,
  surrender_func = function(self, playedTime)
    local surrenderJudge = { { text = "time limitation: 10s", passed = playedTime >= 10 } }
    -- if Self.role ~= "lord" then
      table.insert(surrenderJudge, { text = "1v1: left you alive", passed = true})
    -- end
    return surrenderJudge
  end,
}

Fk:loadTranslationTable{
  ["doublekj_mode"] = "全服2v2抗人机",
  ["#doublekj_rule"] = "全服2v2抗人机",
  ["@[:]doublekjbaner_rule"] = "全服2v2抗人机",
  

  ["doublekj-intro"]="点击介绍",
  [":doublekj-intro"]= desc_doublekj_mode,
  [":doublekj_mode"] = desc_doublekj_mode,
}

return doublekj_mode
